package com.jse;

import java.io.IOException;
import java.util.TimerTask;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import com.jse.cache.Cache;
import com.jse.dao.Dao;
import com.jse.ioc.Ioc;
import com.jse.timer.TaskService;


public class JseServlet extends HttpServlet {
	
	Log log = Logs.get();
	PropertiesProxy conf;
	DataSource dataSource;
	Dao dao;
	Cache cache;
	Ioc ioc;
	ServletContext sc;
	String jjs_suffix;

	@Override
	public void init(ServletConfig config) throws ServletException {
		Jse.setIoc(ioc);
//		ioc = new Ioc(new JsonLoader("bean.js"));
//		conf = ioc.get(PropertiesProxy.class, "conf");
		cache = ioc.get(Cache.class, "cache");
//		dao = ioc.get(Dao.class, "dao");
//		jjs_suffix = conf.containsKey("jjs.suffix") ? conf.get("jjs.suffix") : "jjs";
//		
//		sc = config.getServletContext();
//		Mvcs.setIoc(ioc);
//		Mvcs.setServletContext(sc);
		TaskService taskService =new TaskService(); //ioc.get(TaskService.class, "taskService");
//		if (conf.get("bak").startsWith("true")) {// 数据库备份
//			taskService.exec(new TimerTask() {
//				@Override
//				public void run() {
//					MysqlBak.exec(conf.get("bak.name"), conf.get("db.username"), conf.get("db.password"),
//							conf.get("bak.path"));
//					log.info("mysql bak success!");
//				}
//			}, Times.addDay(Times.day(conf.get("bak.time")), 1));
//		}
		taskService.exec("00 45 07 * *", new TimerTask() {
			@Override
			public void run() {
				log.debug("打印一次");
			}
		});
	}
	
	protected void service(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
		req.setAttribute("home", "xxxxx");
		System.err.println(123);
//		String s=templateEngine.process("index", new WebContext(req, response, req.getServletContext()));
		
		
	}
}
